package com.wnhz.work.yz.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.wnhz.work.yz.BaseActivity;
import com.wnhz.work.yz.R;
import com.wnhz.work.yz.base.BaseRVAdapter;
import com.wnhz.work.yz.base.BaseViewHolder;
import com.wnhz.work.yz.bean.Yasd;
import com.wnhz.work.yz.view.SwitchView;

import org.xutils.x;

import java.util.ArrayList;
import java.util.List;

public class YanShouYiCiActivity extends BaseActivity implements View.OnClickListener {
    private Yasd bean = new Yasd();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_yan_shou_yi_ci);
        TextView title = (TextView) findViewById(R.id.view_main_middle_title);
        findViewById(R.id.btn_main_left).setOnClickListener(this);
        bean = (Yasd) getIntent().getSerializableExtra("bean");
        if (bean == null) {
            MyToast("没有数据");
            return;
        }


        title.setText("" + bean.getInfo().getName());
        TextView name = (TextView) findViewById(R.id.name);
        name.setText("" + bean.getInfo().getBudget_no());
        TextView hetong = (TextView) findViewById(R.id.hetong);
        hetong.setText("合同编号：" + bean.getInfo().getContract_id());
        ImageView img2 = (ImageView) findViewById(R.id.img);
        x.image().bind(img2, bean.getInfo().getImg());
        TextView sname = (TextView) findViewById(R.id.sname);
        sname.setText("" + bean.getInfo().getName());
        TextView install = (TextView) findViewById(R.id.install);
        install.setText("安装队：" + bean.getInfo().getInstall());
        TextView ss = (TextView) findViewById(R.id.ss);
        ss.setText("" + bean.getInfo().getLabel());
        TextView info = (TextView) findViewById(R.id.info);
        info.setText("" + bean.getInfo().getInfo());
        RecyclerView max_re = (RecyclerView) findViewById(R.id.max_re);
        max_re.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
        final List<Yasd.InfoEntity.ProgressEntity> progress = bean.getInfo().getProgress();
        max_re.setAdapter(new BaseRVAdapter(this, progress) {
            @Override
            public int getLayoutId(int viewType) {
                return R.layout.item_yanshou999;
            }

            @Override
            public void onBind(BaseViewHolder holder, int position) {  holder.setTextView(R.id.cishu, "第" + (position + 1) + "次验收");

                holder.setTextView(R.id.fen, progress.get(position).getScore() + "分");
                holder.setTextView(R.id.time, "安装队：" + progress.get(position).getInstaller());
                holder.setTextView(R.id.gai, progress.get(position).getRemark());
                SwitchView switchButton = holder.getView(R.id.switchButton);
                switchButton.setFlag(false);
                if ("1".equals(progress.get(position).getIs_punish())) {
                    switchButton.setOpened(true);
                    holder.getView(R.id.chufa).setVisibility(View.VISIBLE);
                    holder.setTextView(R.id.status55, progress.get(position).getPunish_money());
                    holder.setTextView(R.id.shuoming, progress.get(position).getPunish_remark());
                } else {
                    switchButton.setOpened(false);
                    holder.getView(R.id.chufa).setVisibility(View.GONE);
                }
                holder.setTextView(R.id.time, progress.get(position).getCheck_time());

                RecyclerView diyici = holder.getView(R.id.diyici);
                diyici.setLayoutManager(new GridLayoutManager(YanShouYiCiActivity.this, 4, LinearLayoutManager.VERTICAL, false));
                final List<String> check_img = progress.get(position).getCheck_img();
                diyici.setAdapter(new BaseRVAdapter(YanShouYiCiActivity.this, check_img) {
                    @Override
                    public int getLayoutId(int viewType) {
                        return R.layout.item_photo;
                    }

                    @Override
                    public void onBind(BaseViewHolder holder, final int position) {
                        holder.getImageView(R.id.img).setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                Intent intent = new Intent(YanShouYiCiActivity.this, ShowImageDetail.class);
                                intent.putStringArrayListExtra("paths", (ArrayList<String>) check_img);
                                intent.putExtra("index", position);
                                startActivity(intent);
                            }
                        });
                        //x.image().bind(holder.getImageView(R.id.img), bean.getInfo().getCheck_img().get(position));
                        ImageLoader.getInstance().displayImage(check_img.get(position), holder.getImageView(R.id.img));

                    }

                });


            }


        });


    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_main_left:
                finish();
                break;
        }
    }
}
